-- NewSpeedDungeonsBookView 竞速副本介绍UI

local IconRender = require("app.widget.renders.IconRender")

local RewardPanelNum = 3 -- 奖杯个数
local RewardItemNum = 4 -- 每种奖杯包含的奖励个数
local GRADE_TLT_STR = L("lua_code_text_325")

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.NewSpeedDungeonsBookUi

function ClassRef:init()
	self._ui.Button_close:addClickEventListener(function()
			executeFunc(self._onCloseView, self)
		end)

	self._tltText = self._ui["Panel/Panel_left/tlt"]
	self._descText = self._ui["Panel/Panel_left/Text"]
	self._iconBg = self._ui["Panel/Panel_left/Image"]
	self._leftBtn = self._ui["Panel/Panel_left/Button"]

	self._rightGoBtn = self._ui["Panel/Panel_right/Button"]
	self._rightGoBtn:addClickEventListener(function()
			executeFunc(self._onCloseView, self)
		end)

	self._gradeTltList = {0,0,0} -- 奖励条件文本
	self._gradeStatusList = {0,0,0} -- 奖励
	self._rewardItemList = { {}, {}, {} }
	local idx = 0
	for i = RewardPanelNum, 1, -1 do
		idx = idx + 1
		local panel = self._ui["Panel/Panel_right/Panel_"..i]
		self._gradeTltList[idx] = panel:getChildByName( "tlt" )
		self._gradeStatusList[idx] = panel:getChildByName( "img_own" )
		self._gradeStatusList[idx]:setVisible( false )
		for j = 1, RewardItemNum do
			self._rewardItemList[idx][j] = IconRender.create( panel:getChildByName( "icon_" .. j ) )
			self._rewardItemList[idx][j]:setTipEnable( true )
			self._rewardItemList[idx][j]:setVisible( false )
		end
	end
end

-- teamTarget = TeamTargetVo
function ClassRef:refresh(teamTarget)
	self._tltText:setString(teamTarget:getFullName())

	local speedInfo = teamTarget:getSpeedInfo()
	self._descText:setString(speedInfo:getDesc())
	self._iconBg:loadTexture(speedInfo:getIconBg())

	local grades = speedInfo:getGrades()
	for i,grade in ipairs(grades) do
		self._gradeTltList[i]:setString(string.format(GRADE_TLT_STR, grade.time))
		self._gradeStatusList[i]:setVisible(grade.isGot)
		local renders = self._rewardItemList[i]
		local reewards = grade.rewards
		for j,render in ipairs(renders) do
			render:setVisible(true)
			render:setData(reewards[j])
		end
	end
end

return ClassRef
